import abc
from collections.abc import Iterable, Mapping, Sequence
from typing import Generic, TypeVar

from zkl_aiutils_datasets.basics import Dataset

AnyKey = TypeVar('AnyKey')
AnyDataset = TypeVar('AnyDataset', bound=Dataset)


class GroupedDatasets(Generic[AnyDataset], abc.ABC):
    @property
    @abc.abstractmethod
    def children(self) -> Iterable[AnyDataset]:
        pass


class IndexedDatasets(GroupedDatasets[AnyDataset], abc.ABC):
    @property
    def children(self) -> Iterable[AnyDataset]:
        return self.indexed_children

    @property
    @abc.abstractmethod
    def indexed_children(self) -> Sequence[AnyDataset]:
        pass


class NamedDatasets(GroupedDatasets[AnyDataset], abc.ABC):
    @property
    def children(self) -> Iterable[AnyDataset]:
        return self.named_children.values()

    @property
    @abc.abstractmethod
    def named_children(self) -> Mapping[str, AnyDataset]:
        pass
